<?php

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
JTable::addIncludePath(JPATH_COMPONENT.DIRECTORY_SEPARATOR.'tables');

class KetnoiModelPhanquyen extends JModelLegacy
{
	public function getTable($type = 'Phanquyen', $prefix = 'KetnoiTable', $config = array())
	{
		return JTable::getInstance($type, $prefix, $config);
	}	
    
	function save()
    {
    	$result = array("success"=>true,"error"=>"");
    	$post = JRequest::get("post");
    	$table = $this->getTable();
    	$id = $this->getID();
    	if(!empty($id)) $post["id"] = $id;
    	$table = Utility::save($table, $post);
    	$result["id"] = $table->id;
    	return $result;
    }
    
    function getAssetID()
    {
    	$section = JRequest::getVar("section");
    	$db = JFactory::getDbo();
    	$query = $db->getQuery(true);
    	$query->select("asset_id")
    		  ->from("#__phanquyen")
    		  ->where("section = '$section'");
    	$db->setQuery($query);
    	return $db->loadResult();	  
    }
    
    function getID()
    {
    	$section = JRequest::getVar("section");
    	$db = JFactory::getDbo();
    	$query = $db->getQuery(true);
    	$query->select("id")
    		  ->from("#__phanquyen")
    		  ->where("section = '$section'");
    	$db->setQuery($query);
    	return $db->loadResult();
    }
    
}
